home *** CD-ROM | disk | FTP | other *** search
- Path: RRZ.Uni-Koeln.DE!usenet
- From: Bartosz Borowik <bart>
- Newsgroups: comp.lang.c++
- Subject: Re: Output precision
- Date: 22 Jan 1996 09:48:43 GMT
- Organization: Regional Computing Center, University of Cologne
- Message-ID: <4dvmhr$t39@news.rrz.uni-koeln.de>
- References: <rplDLKLwK.119@netcom.com>
- NNTP-Posting-Host: fileserv2.mi.uni-koeln.de
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 1.1N (X11; I; SunOS 4.1.3 sun4m)
- X-URL: news:rplDLKLwK.119@netcom.com
-
- rpl@netcom.com (Robert Laudati) wrote:
- :It doesn't get too much more basic than this, but I can not
- :set the precision correctly on output. Here's the sample:
- :
- :#include <stdio.h>
- :#include <iostream.h>
- :#include <iomanip.h>
- :
- :int main( int argc, char *argv[])
- :{
- : int i=0;
- : float x=56.0;
- : double y=34.038383999;
- :
- : i = cout.precision(6);
- : printf( "%d %f %lf\n\n", i, x, y );
- : cout << i << " " << x << " " << y << endl;
- : return 0;
- :}
- :
- :Which results in:
- :
- :robl@cosmo<216>: test
- :6 56.000000 34.038384
- :
- :6 56 34.0384
- :robl@cosmo<217>:
-
- You should set an output style for floating numbers before you specify
- the precision:
-
- cout.setf(ios::fixed, ios::floatfield);
- cout.precision(6);
-
- --------------------------------------------------------------------------------
-
- Bartosz Borowik
-
- Universitaet zu Koeln Tel. 0221 / 470-6000
- Zentrum fuer Paralleles Rechnen Fax. 0221 / 470-5160
- Weyertal 80 e-mail: bart@mi.uni-koeln.de
- D - 50931 Koeln http://www.zpr.uni-koeln.de/
- staff/borowik/borowik.html
-
-